/**
 * Created by Administrator on 2018/5/9.
 */

define(function (require,exports,module) {
    var sTpl = require("./template.html");
    require("./query.css");
    var enter= require("../enter/enter.js")
    var VueComponent = Vue.extend({
        template: sTpl,
        components:{
            'enters':enter
        },
        methods: {
            queryFlightInfo:function() {
                var $this=this;
                axios.get("/dam/api/flightTypeInfo/queryFlightTypeInfo?filter="+this.filter).then(function(response){
                    $this.flightInfo = response.data;
                });
            }
            ,show:function(scope){
                this.parentData.showOrEdit="show";
                this.parentData.returnCallbak=function () {
                    $("#panel-activer").prop("checked",false);
                }
                $("#panel-activer").prop("checked",true)
                this.$refs.enters.formInline=scope;

            },edit:function(row,index){
                var $this=this;
                this.parentData.showOrEdit="edit";
                this.parentData.returnCallbak=function () {
                    $("#panel-activer").prop("checked",false);
                }
                this.parentData.dataCallbak=function(data){
                    $this.flightInfo[index]=data;
                }

                $("#panel-activer").prop("checked",true)
                  this.$refs.enters.formInline=row;

            },add:function () {
                var $this=this;
                this.parentData.showOrEdit="add";
                this.parentData.returnCallbak=function () {
                    $("#panel-activer").prop("checked",false);
                }
                this.parentData.dataCallbak=function(data){
                    $this.flightInfo.unshift(data);
                    $("#panel-activer").prop("checked",false);
                }
                this.$refs.enters.formInline=this.$refs.enters.initFormInline();
                $("#panel-activer").prop("checked",true)

            },
            deleteFlightInfo:function (scope,index) {
                var $this=this;
                this.$confirm('删除后将无法恢复', '确定删除该配置信息？', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(function() {
                    axios.post(basepath+'/api/flightTypeInfo/deleteFlightTypeInfo',scope)
                        .then(function (response) {
                            $this.flightInfo.splice(index,1);
                            $this.$notify({
                                title: '删除成功',
                                message: '飞机信息已删除'
                            });
                        });
                })
            }
        },
        data:function () {
            return {
                flightInfo:[],
                filter:"",
                parentData:{showOrEdit:'show',data:{}}
            }
        },
        created:function () {
            this.queryFlightInfo();
        }

    })
    module.exports = VueComponent;
    return VueComponent;
});